package com.neusoft.elmboot.mapper;

import java.util.List;
import org.apache.ibatis.annotations.*;
import com.neusoft.elmboot.po.OrderDetailet;

@Mapper
public interface OrderDetailetMapper {

	@Insert({
			"<script>",
			"insert into orderDetailet(orderId, foodId, quantity) values ",
			"<foreach collection='list' item='od' separator=','>",
			"(#{od.orderId}, #{od.foodId}, #{od.quantity})",
			"</foreach>",
			"</script>"
	})
	int saveOrderDetailetBatch(@Param("list") List<OrderDetailet> list);

	@Select("SELECT * FROM orderDetailet WHERE orderId = #{orderId}")
	@Results(id = "orderDetailetResultMap", value = {
			@Result(column = "odId", property = "odId", id = true),  // 使用 MyBatis 的 id = true 标识主键
			@Result(column = "orderId", property = "orderId"),
			@Result(column = "foodId", property = "foodId"),
			@Result(column = "quantity", property = "quantity"),
			@Result(property = "food", column = "foodId",
					one = @One(select = "com.neusoft.elmboot.mapper.FoodMapper.getFoodById"))
	})
	List<OrderDetailet> listOrderDetailetByOrderId(Integer orderId);
}
